//
//  CinemaListViewController.m
//  UI_豆瓣项目
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 关业达. All rights reserved.
//

#import "CinemaListViewController.h"
#import "Cinema.h"
#import "MBProgressHUD.h"
#import "CinemaListTableViewCell.h"
#import "AppTools.h"
@interface CinemaListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *myTableView;
@property (nonatomic, retain)NSMutableArray *myArray;
@property (nonatomic, retain)MBProgressHUD *hub;



@end

@implementation CinemaListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.530 green:0.930 blue:0.906 alpha:1.000];
    self.navigationItem.title = @"影院";
    
    
    
    [AppTools geturlStr:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php" Block:^(id result) {
        
        self.myArray = [NSMutableArray array];
        NSMutableDictionary *dic = result;
        NSMutableDictionary *dic1 = [dic objectForKey:@"result"];
        NSMutableArray *array = [dic1 objectForKey:@"data"];
        for (NSDictionary *dicX in array) {
            Cinema *cinema = [[Cinema alloc] init];
            // KVC
            [cinema setValuesForKeysWithDictionary:dicX];
            [self.myArray addObject:cinema];
            [cinema release];
            // 刷新
            [self.myTableView reloadData];
            // 停止菊花
            [self.hub hide:YES];
        }
        
        
    }];
    
    
    
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    [_myTableView release];
    
    // 转菊花
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"网速如此的垃圾......";
    
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    CinemaListTableViewCell *cell = [[CinemaListTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    Cinema *cinema = [self.myArray objectAtIndex:indexPath.row];
    cell.acinema = cinema;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 186;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
